package com.jac.qpsc.wxapi;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.example.mylibrarybase.utils.LogUtils;
import com.jac.qpsc.WX.Constants;
import com.tencent.mm.sdk.constants.ConstantsAPI;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.modelpay.PayResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {

	public static final String WX_PAY_ACTION = "com.jac.qpsc.pay.wx_completed";
	private static final String TAG = "MicroMsg.SDKSample.WXPayEntryActivity";
	
    private IWXAPI api;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       // setContentView(R.layout.pay_result);
        
    	api = WXAPIFactory.createWXAPI(this, Constants.APP_ID);
        api.handleIntent(getIntent(), this);
    }

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
        api.handleIntent(intent, this);
	}

	@Override
	public void onReq(BaseReq req) {

	}

	@Override
	public void onResp(BaseResp resp) {
		LogUtils.i("错误码" + resp.errCode);

//		if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
//			AlertDialog.Builder builder = new AlertDialog.Builder(this);
//			builder.setTitle("微信支付");
//			builder.setMessage(""+resp.errCode);
//			builder.show();
//		}
		if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
			PayResp payResp = (PayResp) resp;
			Intent intent = new Intent(WX_PAY_ACTION);
			intent.putExtra("prepay_id",payResp.prepayId);
			sendBroadcast(intent);
		}

		finish();
	}
}